﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Web.Wap.Code;
using ZLCMS.Data.Model;
using NHibernate;
using DotNet.Common.NHibernateUtil;
using Newtonsoft.Json;
using ZLCMS.Business.Util;
using ZLCMS.Commands.Member.Commands.Coupon;
using ZLCMS.Commands.Data;

namespace ZLCMS.Web.Wap.Web
{
    public partial class CouponActivity : MemberPageBase
    {
        protected ShopCouponRule Rule { get; set; }

        protected IList<CouponRuleItem> ItemList { get; set; }

        protected bool CouponGetable { get; set; }

        protected string Background 
        {
            get
            {
                string result = "";
                if (string.IsNullOrEmpty(Rule.BackgroundUrl))
                {
                    result = "/wap/web/images/coupon_header.jpg";
                }
                else
                {
                    result = FileKit.FirstFilePath(Rule.BackgroundUrl);
                }
                return result;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            int uid = Int32.Parse(Request["uid"]);

            using(ISession session = SessionFactoryHelper.CreateSession())
            {
                Rule = session.Get<ShopCouponRule>(uid);

                CouponGetable = GetCouponCommand.CheckCouponGetable(session, Rule, CurrentMemberAccount);
            }
            ItemList = JsonConvert.DeserializeObject<IList<CouponRuleItem>>(Rule.ItemConfig);

        }
    }
}